﻿using System;
using System.Threading;
using blue.communication;

namespace BtcsCon
{
    class Program
    {
        static void Main(string[] args)
        {
            Thread btcs = new Thread(new ThreadStart(btcs_thandler));
            btcs.Start();

            Thread blue = new Thread(new ThreadStart(blue_thandler));
            blue.Start();

            System.Console.ReadKey();
        }

        public static void btcs_thandler(){
            BtcsClient client = new BtcsClient(null,"btcs/pub", "btcs/sub"
                , "127.0.0.1", "btcs-publisher", "btcs-subscriber");
            while(true){
                // Build Message
                string msg = DateTime.Now.ToString();
                // Publish message.
                client.publish("btcs-pub ,"+msg);
                // Waiting for 1 second.
                Thread.Sleep(1000);
            }
        }

        public static void blue_thandler(){
            BtcsClient client = new BtcsClient(msgHandler,"btcs/sub", "btcs/pub"
                , "127.0.0.1", "blue-publisher", "blue-subscriber");

        }

        public static void msgHandler(byte[] msg){
            string  str = System.Text.Encoding.UTF8.GetString(msg);
            System.Console.WriteLine("Recv(Demo) > {0}",str);
        }
    }
}
